package org.bookie.model;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Transient;

import org.bookie.model.operator.Multiply;
import org.bookie.model.operator.Operator;

/**
 * Class modelling a bet slip of type <code>multiple</code>.
 * The profit calculation is delegated to an instance of {@link Operator}.
 * 
 * @author Igor Drobiazko
 */
@Entity
@DiscriminatorValue("M")
public class MultipleBetSlip extends BetSlip {

	private static final long serialVersionUID = 1L;

	/**Used Operator*/
	@Transient
	private static Operator operator = new Multiply();
	
	/**Constructs an empty instance of MultipleBetSlip*/
	protected MultipleBetSlip(){super();}
	
	/**
	 * Constructs a new instance of the MultipleBetSlip. 
	 * @param user owner of the BetSlip to set
	 * @param stake stake to place
	 */
	public MultipleBetSlip(User user, Double stake){
		super(user, stake);
	}
	
	/**
	 * Constructs a new instance of the MultipleBetSlip from another BetSlip. 
	 * @param betSlip BetSlip to create new one from
	 */
	public MultipleBetSlip(BetSlip betSlip) {
		super(betSlip);
	}
	
	/**
	 * Get the {@link Operator}.
	 */
	protected Operator getOperator() {
		return operator;
	}
	
	@Override
	public void recalcProfit() {
		if(isSuccessful()){
			setProfit(getMaximalProfit());
		}
	}
	
	public boolean isSuccessful(){
		for(Wager bet: getBets() ){
			if (!bet.isSuccessful()) {
				return false;
			}
		}
		return true;
	}

	
}
